
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rust知识解释</title>
    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
    <style>
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f8f9fa;
        }
        
        .container {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .content {
            padding: 30px;
        }
        
        h1, h2, h3 {
            color: #2c3e50;
            margin-top: 30px;
            margin-bottom: 15px;
        }
        
        h1 {
            font-size: 2em;
            border-bottom: 3px solid #3498db;
            padding-bottom: 10px;
        }
        
        h2 {
            font-size: 1.5em;
            border-bottom: 2px solid #ecf0f1;
            padding-bottom: 8px;
        }
        
        h3 {
            font-size: 1.2em;
            color: #34495e;
        }
        
        p {
            margin-bottom: 15px;
            text-align: justify;
        }
        
        .code-block {
            background: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            padding: 15px;
            margin: 15px 0;
            overflow-x: auto;
            font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
            font-size: 14px;
            line-height: 1.4;
        }
        
        .inline-code {
            background: #f1f3f4;
            padding: 2px 6px;
            border-radius: 4px;
            font-family: 'Fira Code', monospace;
            font-size: 0.9em;
            color: #d73a49;
        }
        
        .mermaid {
            text-align: center;
            margin: 20px 0;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 6px;
        }
        
        li {
            margin-bottom: 8px;
        }
        
        strong {
            color: #2c3e50;
            font-weight: 600;
        }
        
        em {
            color: #7f8c8d;
            font-style: italic;
        }
        
        @media (max-width: 768px) {
            body {
                padding: 10px;
            }
            
            .content {
                padding: 20px;
            }
            
            h1 {
                font-size: 1.5em;
            }
            
            h2 {
                font-size: 1.3em;
            }
        }
        
    </style>
</head>
<body>
    <div class="container">
        <div class="content">
            <br><h1>Rust生命周期详解</h1><br><br><h2>概念定义</h2><br><strong>生命周期</strong>是Rust中引用保持有效的作用域。<br><br><h2>示例代码</h2><br><pre class="code-block rust"><code>fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {<br>    if x.len() > y.len() { x } else { y }<br>}</code></pre><br><br><h2>流程图</h2><br><pre class="code-block mermaid"><code>graph TD<br>    A[创建引用] --> B[生命周期开始]<br>    B --> C[使用引用]<br>    C --> D[生命周期结束]<br>    D --> E[引用失效]</code></pre><br><br><h2>关键要点</h2><br><li>生命周期确保引用安全</li><br><li>编译器自动推断生命周期</li><br><li>显式标注用于复杂情况</li><br>
        </div>
    </div>
    <script>
        mermaid.initialize({ startOnLoad: true });
        Prism.highlightAll();
    </script>
</body>
</html>
